import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/4 21:25
 * @description
 */
public class Solution2 {
    public static void main(String[] args) {

    }
    public int maxWidthRamp(int[] nums) {
        int ans = 0, n = nums.length, top = 0;
        int[] q = new int[n];
        for(int i = 1; i < n; i++) {
            if(nums[i] < nums[q[top]]) {
                q[++top] = i;
            }
        }

        for(int i = n - 1; i >= 0; i--) {
            while(top >= 0 && nums[i] >= nums[q[top]]) {
                ans = Math.max(ans, i - q[top--]);
            }
        }
        return ans;

    }
}
